#include<bits/stdc++.h>
#define db double
#define pdd pair<db,db>
#define pb emplace_back
#define fi first
#define se second
#define chkmax(x,y) x=max(x,y)
using namespace std;
const int N=1e6+5;
const db eps=1e-9;
int n;
db h[N],r[N],R[N];
vector<pdd> v;
db s1(pdd a,pdd b,db x){
	return (x-a.fi)*(b.se-a.se)/(b.fi-a.fi)+a.se;
}
db s2(pdd a,pdd b,db y){
	return (y-a.se)*(b.fi-a.fi)/(b.se-a.se)+a.fi;
}
void _(db x,db y){
	if(v.empty()||fabs(v.back().fi-x)>eps||fabs(v.back().se-y)>eps) 
	v.pb(x,y);
}
int main(){
	// cerr<<fixed<<setprecision(6);
	cout<<fixed<<setprecision(12);
	freopen("wan.in","r",stdin);
	freopen("wan.out","w",stdout);
	// freopen("wan.err","w",stderr);
	cin.tie(nullptr)->sync_with_stdio(false);
	int i;
	cin>>n;
	for(i=1;i<=n;i++){
		int x,y,z;cin>>x>>y>>z;
		h[i]=x,r[i]=y,R[i]=z;
	}
	v.pb(R[1],h[1]),v.pb(r[1],0);
	
	// cerr<<"i: "<<1<<endl;
	// for(auto p:v) cerr<<p.fi<<' '<<p.se<<endl;
	
	for(i=2;i<=n;i++){
		db h0=v.back().se;
		pdd lst={-2,-2};
		while(!v.empty()&&v.back().fi<R[i]){
			auto x=v.back();lst=x;
			v.pop_back();
			if(x.fi<=r[i]) chkmax(h0,x.se);
			else chkmax(h0,x.se-s1({r[i],0},{R[i],h[i]},x.fi));
			if(v.empty()) break;
			auto y=v.back();
			if(x.fi<=r[i]&&y.fi>=r[i]) chkmax(h0,s1(x,y,r[i]));
			if(x.fi<=R[i]&&y.fi>=R[i]) chkmax(h0,s1(x,y,R[i])-h[i]);
		}
		while(!v.empty()&&v.back().se<h0+h[i]) lst=v.back(),v.pop_back();
		if(v.empty()){
			_(R[i],h0+h[i]);
			_(r[i],h0);
			// v.pb(R[i],h0+h[i]);
			// v.pb(r[i],h0);
			// cerr<<"i: "<<i<<endl;
			// for(auto p:v) cerr<<p.fi<<' '<<p.se<<endl;
			continue;
		}
		// assert(lst.fi>-1);
		_(s2(lst,v.back(),h0+h[i]),h0+h[i]);
		_(R[i],h0+h[i]);
		_(r[i],h0);
		// v.pb(s2(lst,v.back(),h0+h[i]),h0+h[i]);
		// v.pb(R[i],h0+h[i]);
		// v.pb(r[i],h0);
	// 	cerr<<"i: "<<i<<endl;
	// 	for(auto p:v) cerr<<p.fi<<' '<<p.se<<endl;
	}
	cout<<v.front().se;
	return 0;
}
